package com.kunpan.admin.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

//@Aspect
//@Component
public class SqlLoggingAspect {
    private static final Logger logger = LoggerFactory.getLogger(SqlLoggingAspect.class);

    @Around("execution(* com.kunpan.admin.mapper.*.*(..))")
    public Object logSqlExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();
        try {
            return joinPoint.proceed();
        } finally {
            long executionTime = System.currentTimeMillis() - startTime;
            String methodName = joinPoint.getSignature().toShortString();
            logger.info("SQL Execution Time for {}: {} ms", methodName, executionTime);
        }
    }
}
